<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\View;
use Illuminate\Pagination\Paginator;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //将数据分享给所有的应用

        //修改默认的分页样式 改成 bootstrap-4
        Paginator::defaultView('vendor.pagination.bootstrap-4');
        Paginator::defaultSimpleView('vendor.pagination.bootstrap-4');

        //热门文章
        $HotList = DB::table('article')->orderByRaw('visit DESC')->limit(10)->get();

        //获取关键词
        $keyword = request('keyword', '');

        $NavList = DB::table('article_type')->orderBy(DB::raw('RAND()'))->limit(6)->get();

        View::share('keyword', $keyword);
        View::share('HotList', $HotList);
        View::share('NavList', $NavList);
    }
}
